<?php
/**
 * Copyright (c) 2018,2345
 * 摘    要：
 * 作    者：林幸亿
 * 修改日期：2018.05.10
 */

namespace Library;

use \App\Models\Account;


class UIHelper 
{

    /**
     * 修改日期：2018-05-10
     */
    public function __construct()
    {
    }

    /**
     * 功    能：Generate a login or logout link according to the user session
     * 修改日期：2018-05-10
     *
     */
    public static function accountLink()
    {
		$account = new Account();
		if($account->checkAuth() == true) {
			return '<div>
                    <a class="btn btn-warning" href="' . BASE_URL . '/logout">注销 Logout</a>
					</div>';
		}
		else{
			return '<div>
                    <a class="btn btn-primary" href="' . BASE_URL . '/login">登录 Login</a>
					</div>';
		}
    }
	
	/**
     * 功    能：Generate a menu link with active link highlight based on current page
     * 修改日期：2018-05-10
     *
     */
    public static function generateMenu($links)
    {
		$curPageName = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
		$menu = '<ul class="navbar-nav mr-auto">';
		
		foreach($links as $url=>$link)
		{
			
			if($url == $_SERVER['QUERY_STRING'])
			{
				$menu .= '<li class="nav-item active">';
				$menu .= '<a class="nav-link" href="'. BASE_URL . '/' . $url . '">' .$link . '<span class="sr-only">(current)</span></a>';
			}
			else
			{
				$menu .= '<li class="nav-item">';
				$menu .= '<a class="nav-link" href="'. BASE_URL . '/' . $url . '">' .$link . '</a>';
			}	
			$menu .= '</li>';
		}

        $menu .= '</ul>';
		
		return $menu;
	}
	
}
